<script setup>
import { useCouponApi } from '/@/api/coupon';
const { getCouponList } = useCouponApi();
const props = defineProps({
	modelValue: {
		type: Number,
	},
});
const emit = defineEmits(['update:modelValue']);
const selected = computed(() => props.modelValue);
const options = ref([]);
const loading = ref(false);
async function init() {
	try {
		let params = {
			current: 1,
			pageSize: 99,
		};
		loading.value = true;
		let res = await getCouponList(params);
		loading.value = false;
		if (res.code !== 200) return;
		options.value = res.data.data;
	} catch (error) {
		loading.value = false;
	}
}
onMounted(init);
function change(val) {
	emit('update:modelValue', val);
}
</script>
<template>
	<div class="CouponSelector">
		<el-select v-model="selected" clearable :loading="loading" @change="change">
			<el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"> </el-option>
		</el-select>
	</div>
</template>
